<include file='./header' />
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<script type="text/javascript" src="__ROOT__/js/jquery.SuperSlide.js"></script>
<script type="text/javascript">
    var score={$score};
    var arrUserPer= new Array();
    var arrPer = new Array();
    var arrRecommendPer = new Array();
    var chart; 
    
    $(document).ready(function() 
    {
        getRecommendPer();
        getUserproduct();
        
        showpie1();
        showpie2(arrRecommendPer);
        
    });
    
        function getGroupHisdata(xj,zj,gp,ll,type){   
            //alert(xj+"|"+zj+"|"+gp+"|"+ll+"|"+type);
            $.ajax({  
                    type: "post",  
                    url: "__URL__/getGroupHisdata",  
                    dataType: 'json',
                    data: {'xianjin':xj,'zhaijuan':zj,'gupiao':gp,'linglei':ll},
                    beforeSend: function(XMLHttpRequest){   
                    },  
                    error:function(){
                        alert('errorgetGroupHisdata');
                    },
                    async : true,
                    success: function(json)
                    {
                        if(json.status == 1){
                            var data = eval("("+json.data+")");//
                            //alert(data['qzzdsy']);
                            if (type == 'user')
                            {
                                $("#uqzzdsy").text(data['qzzdsy']+"%");
                                $("#usyl").text(data['syl']+"%");
                                $("#tdfx1").text(data['syqj']);
                            }
                            else
                            {
                                $("#rqzzdsy").text(data['qzzdsy']+"%");
                                $("#rsyl").text(data['syl']+"%");
                                $("#tdfx2").text(data['syqj']);
                            }
                            
                        } else
                        {
                            alert('wrong!');
                        }
                    } 
                })
        
    }
    
       function toDecimal2(x) {    
            var f = parseFloat(x);    
            if (isNaN(f)) {    
                return false;    
            }    
            var f = Math.round(x*100)/100;    
            var s = f.toString();    
            var rs = s.indexOf('.');    
            if (rs < 0) {    
                rs = s.length;    
                s += '.';    
            }    
            while (s.length <= rs + 2) {    
                s += '0';    
            }    
            return s;    
        }  
    function getRecommendPer(){
        $.ajax({  
                    type: "post",  
                    url: "__URL__/getRecommendPer",  
                    dataType: 'json',
                    data: {'score':score},
                    beforeSend: function(XMLHttpRequest){   
                    },  
                    error:function(){
                        alert('errorgetRecommendPer');
                    },
                    async : false,
                    success: function(json)
                    {
						//alert(json.data);
                        if(json.status == 1){
                          arrRecommendPer['xianjin'] = parseFloat(json.data['xianjin']['percent']);
                          arrRecommendPer['zhaiquan'] = parseFloat(json.data['zhaiquan']['percent']);
                          arrRecommendPer['gupiao'] = parseFloat(json.data['gupiao']['percent']);
                          arrRecommendPer['linglei'] = parseFloat(json.data['linglei']['percent']);
                          getGroupHisdata(arrRecommendPer['xianjin'],arrRecommendPer['zhaiquan'],arrRecommendPer['gupiao'],arrRecommendPer['linglei'],'reco');
                        } else
                        {
                            alert('wrong!');
                        }
                    } 
                })
    }
    
    
    function getUserproduct(){
       $.ajax({  
                type: "post",  
                url: "__URL__/getUserProduct",  
                dataType: 'json',
                data: {},
                beforeSend: function(XMLHttpRequest){   
                },  
                error:function(){
                    //alert('getUserProduct');
                },
                async : false,
                success: function(json)
                {
                    //alert('success!');
                    if(json.status == 1){
                        arrUserPer['xianjin'] = parseFloat(json.data['xianjin']['sum']);
                        arrUserPer['zhaiquan'] = parseFloat(json.data['zhaiquan']['sum']);
                        arrUserPer['gupiao'] = parseFloat(json.data['gupiao']['sum']);
                        arrUserPer['linglei'] = parseFloat(json.data['linglei']['sum']);
                        if(arrUserPer['xianjin'] == 0 && arrUserPer['zhaiquan'] == 0 && arrUserPer['gupiao'] == 0 && arrUserPer['linglei'] == 0)
                        {
                            var perxj = 0;
                            var perzj = 0;
                            var pergp = 0;
                            var perll = 0;
                        }else{
                            var usersum = arrUserPer['xianjin']+arrUserPer['zhaiquan']+arrUserPer['gupiao']+arrUserPer['linglei'];
                            var perxj = (arrUserPer['xianjin'] / usersum *100).toFixed(2);
                            var perzj = (arrUserPer['zhaiquan'] / usersum*100).toFixed(2);
                            var pergp = (arrUserPer['gupiao'] / usersum*100).toFixed(2);
                            var perll = (arrUserPer['linglei'] / usersum*100).toFixed(2);
                        }
                        getGroupHisdata(perxj,perzj,pergp,perll,'user');
                        var v1,v2,v3,html;
                        $("#productlist").html("");
                        $.each(json.data, function(i, val) {
                            var v1 = val['name'];
                            arrPer[i] = parseFloat(val['percent']);
                            html = zlshow(v1,val['per'],arrRecommendPer[i]);
                            if (val['product'] == null) {
                                v2 = 'nothing';
                            }else{
                               $.each(val['product'], function(j, val2) { 
                                v2 = val2['productname'];
                                html += zlshow2(v2,val2['productper'],val2['comment']);
                                })
                            }
                            $("#productlist").append(html);  
                        });
                    } else
                    {
                        alert('wrong!');
                    }
                } 
            })
    }
    

   //推荐产品列表 
    function zlshow(v1,v2,v3)
    {
     var str = "";
     str += "<tr>\r\n";
     str += "   <td>"+ v1 +"</td>\r\n";
     str += "   <td><span class='percentage-label'>"+ v2 +"%</span><span class='percentage-bar-container'><span class='percentage-bar' style='width:"+ v2 +"%;'></span></span></td>\r\n";
     str += "   <td> <span style='color:#c00e53'>建议调整比例至"+ v3 +"%</span></td>\r\n";
     str += " </tr>\r\n";
     return str;
    }
    
    function zlshow2(v2,percent,comment)
    {
     var str = "";
     str += " <tr class='sub_tr'>\r\n";
     str += "   <td class='sub'>" +v2+ "</td>\r\n";
     str += "   <td>"+ percent +"%</td>\r\n";
     str += "   <td>"+ comment +"</td>\r\n";
     str += " </tr>\r\n";
    return str;
    }

		
 //饼状图1
 function showpie1(){
      $('#pie1').highcharts({
            chart: {
            },
            title: {
                text: '持有资产现状',
                style: { "color": "#c00e53", "fontSize": "16px" ,"fontFamily":"微软雅黑"}       
            },
            tooltip: {
                pointFormat: '{series.name}: <b>￥{point.y:.2f} </b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                            format: '{point.name}: {point.percentage:.2f}%',
                            distance: 5
                    },
                    showInLegend: false,
                    innerSize: '40%'
                },
            },
            legend: {
                        layout: 'horizontal',
                        align: 'center',
                        borderWidth: 0,
                        itemWidth: 190,
                        itemMarginTop: 3,
                        width:380,
                        itemStyle : { 'fontWeight' : 'normal' },
                        floating: false,                
                        labelFormatter: function() {
                            return this.name + "：￥"+Highcharts.numberFormat(this.y)+"["+Highcharts.numberFormat(this.percentage)+"%]";
                        }
                    },
            series: [{
                type: 'pie',
                name: '总金额',
                data: [
                    {name: '现金', y:arrUserPer['xianjin'],color: '#c00e53' },
                    {name: '债券', y:arrUserPer['zhaiquan'],color:'#fcb322' },
                    {name: '股票', y:arrUserPer['gupiao'],color: '#a9d86e' },
                    {name: '另类投资', y:arrUserPer['linglei'],color:'#58c9f3'}
                ]
            }]
        });
 }
		
		
		
//饼状图2
 function showpie2(arrRecommendPer){
     
      $('#pie2').highcharts({
            chart: {
            },
            title: {
                text: '建议',
                style: { "color": "#c00e53", "fontSize": "16px" ,"fontFamily":"微软雅黑"}       
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                            format: '{point.name}: {point.percentage:.2f}%',
                            distance: 5
                    },
                    showInLegend: false,
                    innerSize: '40%'
                },
            },
            legend: {
                        layout: 'horizontal',
                        align: 'center',
                        borderWidth: 0,
                        itemWidth: 190,
                        itemMarginTop: 3,
                        width:380,
                        itemStyle : { 'fontWeight' : 'normal' },
                        floating: false,                
                        labelFormatter: function() {
                            return this.name + "：￥"+Highcharts.numberFormat(this.y)+"["+Highcharts.numberFormat(this.percentage)+"%]";
                        }
                    },
            series: [{
                type: 'pie',
                name: '占投资比例',
                data: [
                    {name: '现金', y:arrRecommendPer['xianjin'],color: '#c00e53' },
                    {name: '债券', y: arrRecommendPer['zhaiquan'],color:'#fcb322' },
                    {name: '股票', y: arrRecommendPer['gupiao'],color: '#a9d86e' },
                    {name: '另类投资', y: arrRecommendPer['linglei'],color:'#58c9f3'}
                ]
            }]
    })
 }
		
</script>

</head>
<body>
<!--顶部开始-->
<include file="./top" />
<!--顶部结束-->
<!--左导航开始-->
<include file="./left" />
<!--左导航结束-->

<!--主体开始-->
<div class="main-content">
    <div class="wrapper">
        <!--投资配置比较开始-->
        <div class="panel">
            <div class="panel-head">
                资产分析
                <div class="right">
                    <a href="javascript:void(0)" class="btn btn-danger"  data-reveal-id="riskTest"><i class="fa fa-check-square-o"></i>重新做投资风险测试</a>
                   
                    <a href="__GROUP__/Analyse/testResult" class="btn btn-info"><i class="fa fa-bar-chart-o"></i>查看我的答题结果分析</a>
                </div>
            </div>
            <div class="panel-body">               
                <!--当前比例-->
                <div class="tb_con left" style="width:50%;">
                    <h1 style="text-align:center;font-size:16px;line-height:40px;">　</h1>
                	<div id="pie1" style="width:100%;height:400px;text-align:center; vertical-align:middle">
                    	<img src="__ROOT__/images/loadingPie.gif" style="margin-top:100px;" />
                    </div>
                   <table class="table zcfx" style="width:80%;margin:auto">

                        <tr>
                            <td>一年平均收益：</td>
                            <td id='usyl' class="text-danger"></td>
                        </tr>
                        <tr>
                            <td>一年收益区间：</td>
                            <td id='tdfx1' class="text-danger"></td>
                        </tr>
                        <tr>
                            <td colspan="2">从5年投资期限来看，95%的概率您的收益会落在此区间。短期投资收益可能明显高于或低于此范围。</td>
                        </tr> 
                    </table>
                </div>
                <!--计算后比例-->
                <div  class="tb_con right" style="width:50%;">
                    <h1 style="text-align:center;font-size:16px;line-height:40px;">您属于<span class="label label-primary "><?php echo $typeName?></span> 客户：</h1>
                	<div id="pie2" style="width:100%;height:400px;text-align:center; vertical-align:middle">
                    	<img src="__ROOT__/images/loadingPie.gif" style="margin-top:100px;" />
                    </div>
                     <table class="table zcfx" style="width:80%;margin:auto">

                        <tr>
                            <td>一年平均收益：</td>
                            <td id='rsyl' class="text-danger"></td>
                        </tr>
                        <tr>
                            <td>一年收益区间：</td>
                            <td id='tdfx2' class="text-danger"></td>
                        </tr>
                        <tr>
                            <td colspan="2">从5年投资期限来看，95%的概率您的收益会落在此区间。短期投资收益可能明显高于或低于此范围。</td>
                        </tr> 
                    </table>
                </div>
                <div class="clear"></div>
          </div>
        </div>
        <!--投资配置比较结束-->
        <!--产品列表开始-->
        <div class="panel">
        	<div class="panel-head">
                <span style="font-weight:bold;" class="text-danger">您现有的金融产品现状分析建议</span>
            </div>
            <!--推荐产品列表-->
            <div class="panel-body score_table">
                <table class="table">
                  <thead>
                      <tr>
                        <th width="20%">资产类别</th>
                        <th width="30%">现状比例</th>
                        <th>建议</th>
                      </tr>
                  </thead>
                  
                  <tbody id="productlist">

                  </tbody>
                </table>
                <!--<div class="blank10"></div>
				<div class="right">
                    <span class="btn btn-success"><i class="fa fa-sign-in"></i>放个人页面</span>
                </div>-->
              <div class="clear"></div>
          </div>
        </div>
        <!--产品列表结束-->
    </div>
</div>
<!--主体结束-->
<!--底部开始-->
<include file="./foot" />

<!--弹出层开始-->
<include file="question" />
<!--弹出层结束-->
</body>
</html>